package com.hfjava.ebook.common;

import java.io.Serializable;

public class JsonResult<T> implements Serializable {

    private int code;
    private String msg;
    private T data;

    public JsonResult() {
    }

    public JsonResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    @Override
    public String toString() {
        return "JsonResult{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <T> JsonResult ok (T data){
        return new JsonResult(200,"success",data);
    }

    public static <T> JsonResult success(String msg){
        return new JsonResult(0,msg,null);
    }

    public static <T> JsonResult fail(String msg){
        return new JsonResult(-1,msg,null);
    }


    public static <T> JsonResult error(String msg){
        return new JsonResult(500,msg,null);
    }

}
